#include <cstdio>
#include <cstring>

struct Trie
{
    Trie *next[ 26 ];
    int count;
    Trie( )
    {
        int i;
        for ( i = 0; i < 26; i++ )
            next[ i ] = NULL;
        count = 0;
    }
};

Trie *head;

void init( )
{
    char data[ 11 ];
    Trie *p;
    int i;
    head = new Trie;
    while ( gets( data ) && data[ 0 ] != '\0' )
    {
        p = head;
        for ( i = 0; i < strlen( data ); i++ )
        {
            if ( p->next[ data[ i ] - 'a' ] == NULL )
                p->next[ data[ i ] - 'a' ] = new Trie;
            p = p->next[ data[ i ] - 'a' ];
            p->count++;
        }
    }
}

void work( )
{
    char data[ 11 ];
    Trie *p;
    int i;
    while ( gets( data ) )
    {
        p = head;
        for ( i = 0; i < strlen( data ); i++ )
        {
            if ( p->next[ data[ i ] - 'a' ] == NULL )
            {
                puts("0");
                break;
            }
            p = p->next[ data[ i ] - 'a' ];
        }
        if ( i == strlen( data ) )
            printf("%d\n", p->count);
    }
}

int main( )
{
    init( );
    work( );
    return 0;
}
